import { Layers, Node, UITransform, SpriteFrame } from "cc";

export const createUINode = (name: string = "", apt: boolean = false) => {
    const node = new Node(name); 
    const transForm = node.addComponent(UITransform);
    if (apt) transForm.setAnchorPoint(0, 1); // 设置左边基点
    node.layer = 1 << Layers.nameToLayer("UI_2D");
    
    return node;
};

const reg = /\((\d+)\)/;
export const getNumberWithinString = (str: string) => parseInt(str.match(reg)[1] || '0');

export const sortSpriteFram = (spriteFrames: SpriteFrame[]) =>
    spriteFrames.sort((a, b) => getNumberWithinString(a.name) - getNumberWithinString(b.name));